import*as e from"../../core/common/common.js";import*as t from"../../core/host/host.js";import*as r from"../../core/i18n/i18n.js";import*as i from"../../core/sdk/sdk.js";import*as o from"../../models/bindings/bindings.js";import*as n from"../../models/extensions/extensions.js";import*as s from"../emulation/emulation.js";import*as a from"../timeline/timeline.js";import*as c from"../../ui/components/buttons/buttons.js";import*as d from"../../ui/components/helpers/helpers.js";import*as l from"../../ui/components/icon_button/icon_button.js";import*as g from"../../ui/legacy/legacy.js";import*as h from"../../ui/lit-html/lit-html.js";import*as p from"../../services/tracing/tracing.js";import*as u from"../../ui/components/menus/menus.js";import*as R from"../../ui/components/dialogs/dialogs.js";import*as w from"./components/components.js";import*as m from"./converters/converters.js";import*as v from"./extensions/extensions.js";import*as S from"./models/models.js";const y=new CSSStyleSheet;y.replaceSync("*{margin:0;padding:0;box-sizing:border-box;font-size:inherit}*:focus,\n*:focus-visible{outline:none}:host{overflow-x:auto}:host,\ndevtools-recording-view,\ndevtools-create-recording-view{display:flex;flex-direction:column;flex:1;min-height:0}.wrapper{display:flex;flex-direction:column;height:100%}.header{background-color:var(--color-background);display:flex;flex-direction:row;align-items:center;border-bottom:1px solid var(--color-details-hairline);padding:0 5px;min-height:29px;max-height:29px;gap:3px}.separator{background-color:var(--color-details-hairline);width:1px;height:17px;margin:0}select{border-radius:2px;border:1px solid transparent;height:24px;max-width:180px;min-width:140px;padding:0 5px;position:relative;color:var(--color-text-primary);background-color:var(--color-background);text-overflow:ellipsis}select:disabled{color:var(--color-input-text-disabled)}select:not([disabled]):hover,\nselect:not([disabled]):focus-visible,\nselect:not([disabled]):active{background-color:var(--color-iconbutton-hover)}select:not([disabled]):focus-visible{box-shadow:0 0 0 2px var(--color-button-outline-focus)}select option{background-color:var(--color-background-elevation-1);color:var(--color-text-primary)}devtools-menu{width:0;height:0;position:absolute}devtools-recording-list-view{overflow:auto}.error{color:var(--color-error-text);border:1px solid var(--color-error-border);background-color:var(--color-error-background);padding:4px}.feedback{margin-left:auto;margin-right:4px}.feedback .x-link{letter-spacing:0.03em;text-decoration-line:underline;font-size:9px;line-height:16px;color:var(--color-text-secondary);outline-offset:3px}.feedback .x-link:focus-visible{outline:-webkit-focus-ring-color auto 1px}.continue-button{border:none;background-color:transparent;width:24px;height:24px;border-radius:2px}.continue-button devtools-icon{width:24px;height:24px;--icon-color:var(--color-primary)}.continue-button:hover,\n.continue-button:focus-visible{background-color:var(--color-iconbutton-hover)}.continue-button:disabled{background:var(--color-background);color:var(--color-text-disabled);cursor:not-allowed}.continue-button:disabled devtools-icon{--icon-color:var(--icon-disabled)}devtools-shortcut-dialog{padding-right:6px}\n/*# sourceURL=recorderController.css */\n");class f extends Event{static eventName="replayfinished";constructor(){super(f.eventName,{bubbles:!0,composed:!0})}}class x extends Event{recording;static eventName="recordingstatechanged";constructor(e){super(x.eventName,{bubbles:!0,composed:!0}),this.recording=e}}var P=Object.freeze({__proto__:null,ReplayFinishedEvent:f,RecordingStateChangedEvent:x}),b=self&&self.__decorate||function(e,t,r,i){var o,n=arguments.length,s=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,i);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(n<3?o(s):n>3?o(t,r,s):o(t,r))||s);return n>3&&s&&Object.defineProperty(t,r,s),s};const{html:E,Decorators:C,LitElement:T}=h,{customElement:k,state:N}=C,$={createRecording:"Create a new recording",importRecording:"Import recording",deleteRecording:"Delete recording",continueReplay:"Continue",stepOverReplay:"Execute one step",exportRecording:"Export",startStopRecording:"Start/Stop recording",replayRecording:"Replay recording",copyShortcut:"Copy recording or selected step",toggleCode:"Toggle code view",export:"Export",exportViaExtensions:"Export via extensions",getExtensions:"Get extensions…",sendFeedback:"Send feedback"},M=r.i18n.registerUIStrings("panels/recorder/RecorderController.ts",$),I=r.i18n.getLocalizedString.bind(void 0,M),B={json:t.UserMetrics.RecordingExported.ToJSON,"@puppeteer/replay":t.UserMetrics.RecordingExported.ToPuppeteerReplay,puppeteer:t.UserMetrics.RecordingExported.ToPuppeteer,lighthouse:t.UserMetrics.RecordingExported.ToLighthouse};let F=class extends T{static styles=[y];#e=S.RecordingStorage.RecordingStorage.instance();#t=S.ScreenshotStorage.ScreenshotStorage.instance();#r=!0;#i={isPlaying:!1,isPausedOnBreakpoint:!1};#o;#n;#s=new Set;#a;#c=new S.RecorderSettings.RecorderSettings;#d=new S.RecorderShortcutHelper.RecorderShortcutHelper;constructor(){super(),this.isRecording=!1,this.isToggling=!1,this.exportMenuExpanded=!1,this.currentPage="StartPage",this.#e.getRecordings().length&&this.#l("AllRecordingsPage");const t=e.Settings.Settings.instance().moduleSetting("textEditorIndent").get();this.#a=Object.freeze([new m.JSONConverter.JSONConverter(t),new m.PuppeteerReplayConverter.PuppeteerReplayConverter(t),new m.PuppeteerConverter.PuppeteerConverter(t),new m.LighthouseConverter.LighthouseConverter(t)]);const r=v.ExtensionManager.ExtensionManager.instance();this.#g(r.extensions()),r.addEventListener(v.ExtensionManager.Events.ExtensionsUpdated,(e=>{this.#g(e.data)})),this.addEventListener("setrecording",(e=>this.#h(e)))}disconnectedCallback(){super.disconnectedCallback(),this.currentRecordingSession&&this.currentRecordingSession.stop()}#g(e){this.extensionConverters=e.filter((e=>e.getCapabilities().includes("export"))).map(((e,t)=>new m.ExtensionConverter.ExtensionConverter(t,e))),this.replayExtensions=e.filter((e=>e.getCapabilities().includes("replay")))}setIsRecordingStateForTesting(e){this.isRecording=e}setRecordingStateForTesting(e){this.#i.isPlaying=e.isPlaying,this.#i.isPausedOnBreakpoint=e.isPausedOnBreakpoint}setCurrentPageForTesting(e){this.#l(e)}getCurrentPageForTesting(){return this.currentPage}getCurrentRecordingForTesting(){return this.currentRecording}getStepBreakpointIndexesForTesting(){return[...this.#s.values()]}#p(){this.importError=void 0}async#u(t){const r=new e.StringOutputStream.StringOutputStream,i=new o.FileUtils.ChunkedFileReader(t,1e7);if(!await i.read(r))throw i.error();let n;try{n=S.SchemaUtils.parse(JSON.parse(r.data()))}catch(e){return void(this.importError=e)}this.#R(await this.#e.saveRecording(n)),this.#l("RecordingPage"),this.#p()}setCurrentRecordingForTesting(e){this.#R(e)}getSectionsForTesting(){return this.sections}#R(e,t={}){const{keepBreakpoints:r=!1,updateSession:i=!1}=t;this.recordingPlayer?.abort(),this.currentStep=void 0,this.recordingError=void 0,this.lastReplayResult=void 0,this.recordingPlayer=void 0,this.#i.isPlaying=!1,this.#i.isPausedOnBreakpoint=!1,this.#s=r?this.#s:new Set,e?(this.currentRecording=e,this.sections=S.Section.buildSections(e.flow.steps),this.settings=this.#w(e.flow),i&&this.currentRecordingSession&&this.currentRecordingSession.overwriteUserFlow(e.flow)):(this.currentRecording=void 0,this.sections=void 0,this.settings=void 0),this.#m()}#l(e){e!==this.currentPage&&(this.previousPage=this.currentPage,this.currentPage=e)}#w(e){const t=e.steps,r=t.findIndex((e=>"navigate"===e.type)),o={timeout:e.timeout};for(let e=r-1;e>=0;e--){const r=t[e];if(o.viewportSettings||"setViewport"!==r.type||(o.viewportSettings=r),!o.networkConditionsSettings&&"emulateNetworkConditions"===r.type){o.networkConditionsSettings={...r};for(const e of[i.NetworkManager.OfflineConditions,i.NetworkManager.Slow3GConditions,i.NetworkManager.Fast3GConditions])i.NetworkManager.networkConditionsEqual({...e,title:e.i18nTitleKey||""},{...r,title:e.i18nTitleKey||""})&&(o.networkConditionsSettings.title=e.title instanceof Function?e.title():e.title,o.networkConditionsSettings.i18nTitleKey=e.i18nTitleKey)}}return o}#v(){const e=i.TargetManager.TargetManager.instance().primaryPageTarget();if(!e)throw new Error("Missing main page target");return e}#S(e){if(!this.sections)return null;for(const t of this.sections)if(-1!==t.steps.indexOf(e))return t;return null}#m(){if(!this.sections||!this.currentRecording)return;const e=this.currentRecording.storageName;for(let t=0;t<this.sections.length;t++){const r=this.#t.getScreenshotForSection(e,t);this.sections[t].screenshot=r||void 0}this.requestUpdate()}#y(){this.recordingPlayer?.abort()}async#f(e){if(!this.currentRecording||!this.#r)return;const r=n.RecorderPluginManager.RecorderPluginManager.instance().once(n.RecorderPluginManager.Events.ShowViewRequested);e.replay(this.currentRecording.flow);const i=await r;this.viewDescriptor=i,t.userMetrics.recordingReplayStarted(t.UserMetrics.RecordingReplayStarted.ReplayViaExtension)}async#x(e){if(!this.currentRecording||!this.#r)return;if(this.viewDescriptor&&(this.viewDescriptor=void 0),e.data.extension)return this.#f(e.data.extension);t.userMetrics.recordingReplayStarted("chrome_recorder"!==e.data.targetPanel?t.UserMetrics.RecordingReplayStarted.ReplayWithPerformanceTracing:t.UserMetrics.RecordingReplayStarted.ReplayOnly),this.#i.isPlaying=!0,this.currentStep=void 0,this.recordingError=void 0,this.lastReplayResult=void 0;const r=this.currentRecording;this.#p(),await this.#P(),this.recordingPlayer=new S.RecordingPlayer.RecordingPlayer(this.currentRecording.flow,{speed:e.data.speed,breakpointIndexes:this.#s});const i="timeline"===e.data.targetPanel,o=new Set;this.recordingPlayer.addEventListener("Step",(async({data:{step:e,resolve:t}})=>{this.currentStep=e;const i=this.#S(e);if(this.sections&&i&&!o.has(i)){o.add(i);const e=this.sections.indexOf(i),t=await S.ScreenshotUtils.takeScreenshot();i.screenshot=t,S.ScreenshotStorage.ScreenshotStorage.instance().storeScreenshotForSection(r.storageName,e,t)}t()})),this.recordingPlayer.addEventListener("Stop",(()=>{this.#i.isPausedOnBreakpoint=!0,this.requestUpdate()})),this.recordingPlayer.addEventListener("Continue",(()=>{this.#i.isPausedOnBreakpoint=!1,this.requestUpdate()})),this.recordingPlayer.addEventListener("Error",(({data:e})=>{this.recordingError=e,i||(this.#i.isPlaying=!1,this.recordingPlayer=void 0),this.lastReplayResult="Failure";const r=e.message.toLowerCase();r.startsWith("could not find element")?t.userMetrics.recordingReplayFinished(t.UserMetrics.RecordingReplayFinished.TimeoutErrorSelectors):r.startsWith("waiting for target failed")?t.userMetrics.recordingReplayFinished(t.UserMetrics.RecordingReplayFinished.TimeoutErrorTarget):t.userMetrics.recordingReplayFinished(t.UserMetrics.RecordingReplayFinished.OtherError)})),this.recordingPlayer.addEventListener("Done",(()=>{i||(this.#i.isPlaying=!1,this.recordingPlayer=void 0),this.lastReplayResult="Success",this.dispatchEvent(new f),t.userMetrics.recordingReplayFinished(t.UserMetrics.RecordingReplayFinished.Success)})),this.recordingPlayer.addEventListener("Abort",(()=>{this.currentStep=void 0,this.recordingError=void 0,this.lastReplayResult=void 0,this.#i.isPlaying=!1}));let n=e=>{};const s=new Promise((e=>{n=e}));let c=null;if("timeline"===e.data?.targetPanel)c=new p.PerformanceTracing.PerformanceTracing(this.#v(),{tracingBufferUsage(){},eventsRetrievalProgress(){},tracingComplete(e){n(e)}});if(c&&await c.start(),this.#b(!1),await this.recordingPlayer.play(),this.#b(!0),c){await c.stop();const t=await s;if(this.#i.isPlaying=!1,this.recordingPlayer=void 0,await g.InspectorView.InspectorView.instance().showPanel(e.data?.targetPanel),"timeline"===e.data?.targetPanel)a.TimelinePanel.TimelinePanel.instance().loadFromEvents(t)}}async#P(){try{const e=s.DeviceModeWrapper.DeviceModeWrapper.instance();if(e.isDeviceModeOn()){e.toggleDeviceMode();const t=this.#v().model(i.EmulationModel.EmulationModel);await(t?.emulateDevice(null))}}catch{}}#b(e){this.#v().model(i.EmulationModel.EmulationModel)?.setTouchEmulationAllowed(e)}async#h(e){const t=JSON.parse(e.detail);this.#R(await this.#e.saveRecording(S.SchemaUtils.parse(t))),this.#l("RecordingPage"),this.#p()}getUserFlow(){return this.currentRecording?.flow}async#E(e){if(!this.currentRecording)throw new Error("Current recording expected to be defined.");const t={...this.currentRecording,flow:{...this.currentRecording.flow,steps:this.currentRecording.flow.steps.map((t=>t===e.currentStep?e.newStep:t))}};this.#R(await this.#e.updateRecording(t.storageName,t.flow),{keepBreakpoints:!0,updateSession:!0})}async#C(e){if(!this.currentRecording)throw new Error("Current recording expected to be defined.");const r=e.stepOrSection;let i,o=e.position;if("steps"in r){const t=this.sections?.indexOf(r);if(void 0===t||-1===t)throw new Error("There is no section to add a step to");if("after"===e.position)this.sections?.[t].steps.length?(i=this.sections?.[t].steps[0],o="before"):(i=this.sections?.[t].causingStep,o="after");else{if(t<=0)throw new Error("There is no section to add a step to");const e=this.sections?.[t-1];i=e?.steps[e.steps.length-1],o="after"}}else i=r;if(!i)throw new Error("Anchor step is not found when adding a step");const n=this.currentRecording.flow.steps,s=n.indexOf(i)+("before"===o?0:1);n.splice(s,0,{type:S.Schema.StepType.WaitForElement,selectors:["body"]});const a={...this.currentRecording,flow:{...this.currentRecording.flow,steps:n}};t.userMetrics.recordingEdited(t.UserMetrics.RecordingEdited.StepAdded),this.#s=new Set([...this.#s.values()].map((e=>s>e?e:e+1))),this.#R(await this.#e.updateRecording(a.storageName,a.flow),{keepBreakpoints:!0,updateSession:!0})}async#T(e){if(!this.currentRecording)throw new Error("Current recording expected to be defined.");const t={...this.currentRecording.flow,title:e.title};this.#R(await this.#e.updateRecording(this.currentRecording.storageName,t))}async#k(e){if(!this.currentRecording)throw new Error("Current recording expected to be defined.");const r=this.currentRecording.flow.steps,i=r.indexOf(e.step);r.splice(i,1);const o={...this.currentRecording.flow,steps:r};t.userMetrics.recordingEdited(t.UserMetrics.RecordingEdited.StepRemoved),this.#s=new Set([...this.#s.values()].map((e=>i>e?e:i===e?-1:e-1)).filter((e=>e>=0))),this.#R(await this.#e.updateRecording(this.currentRecording.storageName,o),{keepBreakpoints:!0,updateSession:!0})}async#N(e){if(!this.currentRecording)throw new Error("Current recording expected to be defined.");const t=this.currentRecording.flow.steps.findIndex((e=>"navigate"===e.type));if(-1===t)throw new Error("Current recording does not have a navigate step");const r=this.currentRecording.flow.steps.findIndex(((e,r)=>!(r>=t)&&"emulateNetworkConditions"===e.type));if(e.data)if(-1===r)this.currentRecording.flow.steps.splice(0,0,S.SchemaUtils.createEmulateNetworkConditionsStep({download:e.data.download,upload:e.data.upload,latency:e.data.latency}));else{const t=this.currentRecording.flow.steps[r];t.download=e.data.download,t.upload=e.data.upload,t.latency=e.data.latency}else-1!==r&&this.currentRecording.flow.steps.splice(r,1);this.#R(await this.#e.updateRecording(this.currentRecording.storageName,this.currentRecording.flow))}async#$(e){if(!this.currentRecording)throw new Error("Current recording expected to be defined.");this.currentRecording.flow.timeout=e.data,this.#R(await this.#e.updateRecording(this.currentRecording.storageName,this.currentRecording.flow))}async#M(e){if(e.stopPropagation(),e instanceof w.RecordingListView.DeleteRecordingEvent)await this.#e.deleteRecording(e.storageName),this.#t.deleteScreenshotsForRecording(e.storageName),this.requestUpdate();else{if(!this.currentRecording)return;await this.#e.deleteRecording(this.currentRecording.storageName),this.#t.deleteScreenshotsForRecording(this.currentRecording.storageName)}(await this.#e.getRecordings()).length?this.#l("AllRecordingsPage"):this.#l("StartPage"),this.#R(void 0),this.#p()}#I(e){e?.stopPropagation(),this.#l("CreateRecordingPage"),this.#p()}async#B(e){await this.#P(),this.isToggling=!0,this.#p(),t.userMetrics.recordingToggled(t.UserMetrics.RecordingToggled.RecordingStarted),this.currentRecordingSession=new S.RecordingSession.RecordingSession(this.#v(),{title:e.name,selectorAttribute:e.selectorAttribute,selectorTypesToRecord:e.selectorTypesToRecord.length?e.selectorTypesToRecord:Object.values(S.Schema.SelectorType)}),this.#R(await this.#e.saveRecording(this.currentRecordingSession.cloneUserFlow()));let r,i=-1;const o=async e=>{if(!this.sections)throw new Error("Could not find sections.");const t=this.sections.length-1,o=this.sections[t];if(r||i===t)return;r=S.ScreenshotUtils.takeScreenshot();const n=await r;r=void 0,o.screenshot=n,S.ScreenshotStorage.ScreenshotStorage.instance().storeScreenshotForSection(e.storageName,t,n),i=t,this.#m()};this.currentRecordingSession.addEventListener("recordingupdated",(async({data:e})=>{if(!this.currentRecording)throw new Error("No current recording found");this.#R(await this.#e.updateRecording(this.currentRecording.storageName,e));const t=this.shadowRoot?.querySelector("devtools-recording-view");t?.scrollToBottom(),await o(this.currentRecording)})),this.currentRecordingSession.addEventListener("recordingstopped",(async({data:e})=>{if(!this.currentRecording)throw new Error("No current recording found");t.userMetrics.keyboardShortcutFired("chrome_recorder.start-recording"),this.#R(await this.#e.updateRecording(this.currentRecording.storageName,e)),await this.#F()})),await this.currentRecordingSession.start(),this.isToggling=!1,this.isRecording=!0,this.#l("RecordingPage"),this.dispatchEvent(new x(this.currentRecording.flow))}async#F(){if(!this.currentRecording||!this.currentRecordingSession)throw new Error("Recording was never started");this.isToggling=!0,this.#p(),t.userMetrics.recordingToggled(t.UserMetrics.RecordingToggled.RecordingFinished),await this.currentRecordingSession.stop(),this.currentRecordingSession=void 0,this.isToggling=!1,this.isRecording=!1,this.dispatchEvent(new x(this.currentRecording.flow))}async#A(){this.previousPage&&this.#l(this.previousPage)}async#V(e){const t=e instanceof w.RecordingListView.OpenRecordingEvent||e instanceof w.RecordingListView.PlayRecordingEvent?e.storageName:e.target?.value;this.#R(await this.#e.getRecording(t)),this.currentRecording?this.#l("RecordingPage"):"StartPage"===t?this.#l("StartPage"):"AllRecordingsPage"===t&&this.#l("AllRecordingsPage")}async#O(e){if("string"!=typeof e.itemValue)throw new Error("Invalid export option value");if("get-extensions-link"===e.itemValue)return void t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab("https://goo.gle/recorder-extension-list");if(!this.currentRecording)throw new Error("No recording selected");const r=e.itemValue,i=e=>e.getId()===r,o=this.#a.find(i)||this.extensionConverters.find(i);if(!o)throw new Error("No recording selected");const[n]=await o.stringify(this.currentRecording.flow);await this.#U(o.getFilename(this.currentRecording.flow),n);const s=B[o.getId()];if(s)t.userMetrics.recordingExported(s);else{if(!o.getId().startsWith(m.ExtensionConverter.EXTENSION_PREFIX))throw new Error("Could not find a metric for the export option with id = "+r);t.userMetrics.recordingExported(t.UserMetrics.RecordingExported.ToExtension)}}async#U(e,t){try{const r=await window.showSaveFilePicker({suggestedName:e}),i=await r.createWritable();await i.write(t),await i.close()}catch(e){if("AbortError"===e.name)return;throw e}}async#_(){if(!this.currentRecordingSession||!this.currentRecording)return;const e=this.currentRecordingSession.cloneUserFlow();e.steps.push({type:"waitForElement",selectors:[[".cls"]]}),this.#R(await this.#e.updateRecording(this.currentRecording.storageName,e),{keepBreakpoints:!0,updateSession:!0}),t.userMetrics.recordingAssertion(t.UserMetrics.RecordingAssertion.AssertionAdded),await this.updateComplete,this.renderRoot.querySelector("devtools-recording-view")?.shadowRoot?.querySelector(".section:last-child devtools-step-view:last-of-type")?.shadowRoot?.querySelector(".action")?.click()}#D(e){e.stopPropagation(),this.#p(),this.#o=g.UIUtils.createFileSelectorElement(this.#u.bind(this)),this.#o.click()}async#j(e){await this.#V(e),await this.#x(new w.RecordingView.PlayRecordingEvent({targetPanel:"chrome_recorder",speed:this.#c.speed}))}#L=e=>{this.#s.add(e.index),this.recordingPlayer?.updateBreakpointIndexes(this.#s),this.requestUpdate()};#q=e=>{this.#s.delete(e.index),this.recordingPlayer?.updateBreakpointIndexes(this.#s),this.requestUpdate()};#W(){this.viewDescriptor=void 0}handleActions(e){if(this.isActionPossible(e))switch(e){case"chrome_recorder.create-recording":return void this.#I();case"chrome_recorder.start-recording":if("CreateRecordingPage"===this.currentPage||this.isRecording)if("CreateRecordingPage"===this.currentPage){const e=this.renderRoot.querySelector("devtools-create-recording-view");e&&this.#d.handleShortcut(e.startRecording.bind(e))}else this.isRecording&&this.#F();else this.#d.handleShortcut(this.#B.bind(this,new w.CreateRecordingView.RecordingStartedEvent(this.#c.defaultTitle,this.#c.defaultSelectors,this.#c.selectorAttribute)));return;case"chrome_recorder.replay-recording":return void this.#x(new w.RecordingView.PlayRecordingEvent({targetPanel:"chrome_recorder",speed:this.#c.speed}));case"chrome_recorder.toggle-code-view":{const e=this.renderRoot.querySelector("devtools-recording-view");return void(e&&e.showCodeToggle())}}}isActionPossible(e){switch(e){case"chrome_recorder.create-recording":return!this.isRecording&&!this.#i.isPlaying;case"chrome_recorder.start-recording":return!this.#i.isPlaying;case"chrome_recorder.replay-recording":return"RecordingPage"===this.currentPage&&!this.#i.isPlaying;case"chrome_recorder.toggle-code-view":return"RecordingPage"===this.currentPage}}#z(){const e=e=>g.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction(e).map((e=>e.title()));return[{title:I($.startStopRecording),bindings:e("chrome_recorder.start-recording")},{title:I($.replayRecording),bindings:e("chrome_recorder.replay-recording")},{title:I($.copyShortcut),bindings:[""+(t.Platform.isMac()?"⌘ C":"Ctrl+C")]},{title:I($.toggleCode),bindings:e("chrome_recorder.toggle-code-view")}]}#H(){switch(this.currentPage){case"StartPage":return this.#G();case"AllRecordingsPage":return this.#J();case"RecordingPage":return this.#K();case"CreateRecordingPage":return this.#X()}}#J(){const e=this.#e.getRecordings();return E` <${w.RecordingListView.RecordingListView.litTagName} .recordings="${e.map((e=>({storageName:e.storageName,name:e.flow.title})))}" .replayAllowed="${this.#r}" @createrecording="${this.#I}" @deleterecording="${this.#M}" @openrecording="${this.#V}" @playrecording="${this.#j}"> </${w.RecordingListView.RecordingListView.litTagName}> `}#G(){return E` <${w.StartView.StartView.litTagName} @createrecording="${this.#I}"></${w.StartView.StartView.litTagName}> `}#K(){return E` <${w.RecordingView.RecordingView.litTagName} .data="${{recording:this.currentRecording?.flow,replayState:this.#i,isRecording:this.isRecording,recordingTogglingInProgress:this.isToggling,currentStep:this.currentStep,currentError:this.recordingError,sections:this.sections,settings:this.settings,recorderSettings:this.#c,lastReplayResult:this.lastReplayResult,replayAllowed:this.#r,breakpointIndexes:this.#s,builtInConverters:this.#a,extensionConverters:this.extensionConverters,replayExtensions:this.replayExtensions,extensionDescriptor:this.viewDescriptor}}" @networkconditionschanged="${this.#N}" @timeoutchanged="${this.#$}" @requestselectorattribute="${e=>{e.send(this.currentRecording?.flow.selectorAttribute)}}" @recordingfinished="${this.#F}" @stepchanged="${this.#E.bind(this)}" @recordingtitlechanged="${this.#T.bind(this)}" @addstep="${this.#C.bind(this)}" @removestep="${this.#k.bind(this)}" @addbreakpoint="${this.#L}" @removebreakpoint="${this.#q}" @playrecording="${this.#x}" @abortreplay="${this.#y}" @recorderextensionviewclosed="${this.#W}" @addassertion="${this.#_}"></${w.RecordingView.RecordingView.litTagName}> `}#X(){return E` <${w.CreateRecordingView.CreateRecordingView.litTagName} .data="${{recorderSettings:this.#c}}" @recordingstarted="${this.#B}" @recordingcancelled="${this.#A}"></${w.CreateRecordingView.CreateRecordingView.litTagName}> `}#Q=()=>{if(!this.#n)throw new Error("#exportMenuButton not found");return this.#n};#Y(e){e.stopPropagation(),this.#p(),this.exportMenuExpanded=!this.exportMenuExpanded}#Z(){this.exportMenuExpanded=!1}render(){const e=this.#e.getRecordings(),t=this.currentRecording?this.currentRecording.storageName:this.currentPage,r=[0===e.length?{value:"StartPage",name:"No recordings",selected:"StartPage"===t}:{value:"AllRecordingsPage",name:`${e.length} recording(s)`,selected:"AllRecordingsPage"===t},...e.map((e=>({value:e.storageName,name:e.flow.title,selected:t===e.storageName})))];return E` <div class="wrapper"> <div class="header"> <${c.Button.Button.litTagName} @click="${this.#I}" .data="${{variant:"toolbar",iconName:"plus",disabled:this.#i.isPlaying||this.isRecording||this.isToggling,title:S.Tooltip.getTooltipForActions(I($.createRecording),"chrome_recorder.create-recording")}}"></${c.Button.Button.litTagName}> <div class="separator"></div> <select .disabled="${0===e.length||this.#i.isPlaying||this.isRecording||this.isToggling}" @click="${e=>e.stopPropagation()}" @change="${this.#V}"> ${h.Directives.repeat(r,(e=>e.value),(e=>E`<option .selected="${e.selected}" value="${e.value}">${e.name}`))} </select> <div class="separator"></div> <${c.Button.Button.litTagName} @click="${this.#D}" .data="${{variant:"toolbar",iconName:"import",title:I($.importRecording)}}"></${c.Button.Button.litTagName}> <${c.Button.Button.litTagName} id="origin" @click="${this.#Y}" on-render="${d.Directives.nodeRenderedCallback((e=>{this.#n=e}))}" .data="${{variant:"toolbar",iconName:"download",title:I($.exportRecording),disabled:!this.currentRecording}}"></${c.Button.Button.litTagName}> <${u.Menu.Menu.litTagName} @menucloserequest="${this.#Z}" @menuitemselected="${this.#O}" .origin="${this.#Q}" .showDivider="${!1}" .showSelectedItem="${!1}" .showConnector="${!1}" .open="${this.exportMenuExpanded}"> <${u.Menu.MenuGroup.litTagName} .name="${I($.export)}"> ${h.Directives.repeat(this.#a,(e=>E` <${u.Menu.MenuItem.litTagName} .value="${e.getId()}"> ${e.getFormatName()} </${u.Menu.MenuItem.litTagName}> `))} </${u.Menu.MenuGroup.litTagName}> <${u.Menu.MenuGroup.litTagName} .name="${I($.exportViaExtensions)}"> ${h.Directives.repeat(this.extensionConverters,(e=>E` <${u.Menu.MenuItem.litTagName} .value="${e.getId()}"> ${e.getFormatName()} </${u.Menu.MenuItem.litTagName}> `))} <${u.Menu.MenuItem.litTagName} .value="${"get-extensions-link"}"> ${I($.getExtensions)} </${u.Menu.MenuItem.litTagName}> </${u.Menu.MenuGroup.litTagName}> </${u.Menu.Menu.litTagName}> <${c.Button.Button.litTagName} @click="${this.#M}" .data="${{variant:"toolbar",iconName:"bin",disabled:!this.currentRecording||this.#i.isPlaying||this.isRecording||this.isToggling,title:I($.deleteRecording)}}"></${c.Button.Button.litTagName}> <div class="separator"></div> <button class="continue-button" .disabled="${!this.recordingPlayer||!this.#i.isPausedOnBreakpoint}" title="${I($.continueReplay)}" @click="${()=>this.recordingPlayer?.continue()}"> <${l.Icon.Icon.litTagName} .data="${{iconName:"resume",color:"var(--icon-color)"}}"></${l.Icon.Icon.litTagName}> </button> <${c.Button.Button.litTagName} @click="${()=>this.recordingPlayer?.stepOver()}" .data="${{variant:"toolbar",iconName:"step-over",disabled:!this.recordingPlayer||!this.#i.isPausedOnBreakpoint,title:I($.stepOverReplay)}}"></${c.Button.Button.litTagName}> <div class="feedback"> <x-link class="x-link" href="${w.StartView.FEEDBACK_URL}">${I($.sendFeedback)}</x-link> </div> <div class="separator"></div> <${R.ShortcutDialog.ShortcutDialog.litTagName} .data="${{shortcuts:this.#z()}}"></${R.ShortcutDialog.ShortcutDialog.litTagName}> </div> ${this.importError?E`<div class="error">Import error: ${this.importError.message}</div>`:""} ${this.#H()} </div> `}};b([N()],F.prototype,"currentRecordingSession",void 0),b([N()],F.prototype,"currentRecording",void 0),b([N()],F.prototype,"currentStep",void 0),b([N()],F.prototype,"recordingError",void 0),b([N()],F.prototype,"isRecording",void 0),b([N()],F.prototype,"isToggling",void 0),b([N()],F.prototype,"recordingPlayer",void 0),b([N()],F.prototype,"lastReplayResult",void 0),b([N()],F.prototype,"currentPage",void 0),b([N()],F.prototype,"previousPage",void 0),b([N()],F.prototype,"sections",void 0),b([N()],F.prototype,"settings",void 0),b([N()],F.prototype,"importError",void 0),b([N()],F.prototype,"exportMenuExpanded",void 0),b([N()],F.prototype,"extensionConverters",void 0),b([N()],F.prototype,"replayExtensions",void 0),b([N()],F.prototype,"viewDescriptor",void 0),F=b([k("devtools-recorder-controller")],F);var A=Object.freeze({__proto__:null,get RecorderController(){return F}});let V,O;class U extends g.Panel.Panel{static panelName="chrome_recorder";#ee;constructor(){super(U.panelName),this.#ee=new F,this.contentElement.append(this.#ee),this.contentElement.style.minWidth="400px"}static instance(e={forceNew:null}){const{forceNew:t}=e;return V&&!t||(V=new U),V}wasShown(){g.Context.Context.instance().setFlavor(U,this),this.#ee.focus()}willHide(){g.Context.Context.instance().setFlavor(U,null)}handleActions(e){this.#ee.handleActions(e)}isActionPossible(e){return this.#ee.isActionPossible(e)}}class _{static instance(e={forceNew:null}){const{forceNew:t}=e;return O&&!t||(O=new _),O}handleAction(e,t){return(async()=>{await g.ViewManager.ViewManager.instance().showView(U.panelName);const e=g.ViewManager.ViewManager.instance().view(U.panelName);if(e){(await e.widget()).handleActions(t)}})(),!0}}var D=Object.freeze({__proto__:null,RecorderPanel:U,ActionDelegate:_});export{A as RecorderController,P as RecorderEvents,D as RecorderPanel};
